public  class  publicLib{ 
  


	///the process is java.lang.process
 public static void runRootCommand(String command){
        
        Process process = null;
       
        DataOutputStream os2 = new DataOutputStream(process.getOutputStream());
        try {
            process = Runtime.getRuntime().exec("su"); //it will auto next line
           
           
                os2.writeBytes(new StringBuilder(String.valueOf(command)).append("\n").toString());
               //need  enter huiche
			   os2.writeBytes("exit\n");
                os2.flush();
                process.waitFor();
        }catch(Exception e){
            
            e.printStackTrace();
        }finally{
            try{
            
            if(os2 != null){
                
                os2.close();
            }
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
	 public static boolean hasRootPermission(){


        java.lang.Process process =null;
        DataOutputStream os = null;
        boolean rooted = true;
        try{

            process =Runtime.getRuntime().exec("su");
            DataOutputStream os2 = new DataOutputStream(process.getOutputStream());


            os2.writeBytes("exit\n");
            os2.flush();
            process.waitFor();
            if(process.exitValue() != 0){

                rooted = false;
            }else{

                rooted = true;
            }

        }catch (Exception e){

            e.printStackTrace();
            return false;
        }finally {

            try {
                if (os != null) {

                    os.close();
                    process.destroy();
                }
            }catch (Exception e){

                e.printStackTrace();
            }

        }

        return rooted;

    }
////////////////////////////////////
  private static byte[] hexStringToByteArray(String s)
  {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
      data[(i / 2)] = 
        ((byte)((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)));
    }
    return data;
  }


private static String byteArrayToHexString(byte[] data)
    {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++)
        {
            int halfbyte = data[i] >>> 4 & 0xF;
            int two_halfs = 0;
            do
            {
                if ((halfbyte >= 0) && (halfbyte <= 9)) {
                    buf.append((char)(48 + halfbyte));
                } else {
                    buf.append((char)(97 + (halfbyte - 10)));
                }
                halfbyte = data[i] & 0xF;
            } while (

                    two_halfs++ < 1);
        }
        return buf.toString();
    }


     public  String  md5sum(String  input){

        MessageDigest md5Obj = null;

        try
        {
            md5Obj = MessageDigest.getInstance("MD5");
        }
        catch (Exception e)
        {
            System.out.println("Hash Algorithm not supported");
            System.exit(-1);
        }
        byte[] hashBytes = new byte[40];
        md5Obj.update(input.getBytes(), 0, input.length());
        hashBytes = md5Obj.digest();
        System.out.println(byteArrayToHexString(hashBytes));
            /*     MessageDigest md5 =MessageDigest.getInstance("MD5");
        String  a=new String (byteArrayToHexString(md5.digest("123456".getBytes())));
        System.out.println(a);*/
        return   byteArrayToHexString(hashBytes);

    }
//des解密后必须用bytetoHexString 还原  aes解密后可以直接看
//des is duichen jiami  so use more litle   it need a key  to ciper or deciper
   public static byte[] DESdecrypt(byte[] src, String password) throws Exception {
// DES算法要求有一个可信任的随机数源
        SecureRandom random = new SecureRandom();
// 创建一个DESKeySpec对象
        DESKeySpec desKey = new DESKeySpec(password.getBytes());
// 创建一个密匙工厂
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
// 将DESKeySpec对象转换成SecretKey对象
        SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成解密操作
        Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
        cipher.init(Cipher.DECRYPT_MODE, securekey, random);
// 真正开始解密操作
        return cipher.doFinal(src);
    }
    public static byte[] DESencrypt(byte[] datasource, String password) {
        try{
            SecureRandom random = new SecureRandom();
            DESKeySpec desKey = new DESKeySpec(password.getBytes());
//创建一个密匙工厂，然后用它把DESKeySpec转换成
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
            SecretKey securekey = keyFactory.generateSecret(desKey);
//Cipher对象实际完成加密操作
            Cipher cipher = Cipher.getInstance("DES");
//用密匙初始化Cipher对象
            cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
//现在，获取数据并加密
//正式执行加密操作
            return cipher.doFinal(datasource);
        }catch(Throwable e){
            e.printStackTrace();
        }
        return null;
    }
   
///////////////////////////////aes
//decrypt get  result  don't use  bytetoString  direct  to  new String (byte[]b )
//解密后的不用转化直接string new就可以了
     public static byte[] AESDecrypt(byte[] content, String password) {
        try {
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            kgen.init(128, new SecureRandom(password.getBytes()));
            SecretKey secretKey = kgen.generateKey();
            byte[] enCodeFormat = secretKey.getEncoded();
            SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
            Cipher cipher = Cipher.getInstance("AES");// 创建密码器
            cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
            byte[] result = cipher.doFinal(content);
            return result; // 加密
        } catch (Exception e) {
            e.printStackTrace();

        }
        return null;
    }
    public static byte[] AESEncrypt(String content, String password) {
        try {
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            kgen.init(128, new SecureRandom(password.getBytes()));
            SecretKey secretKey = kgen.generateKey();
            byte[] enCodeFormat = secretKey.getEncoded();
            SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
            Cipher cipher = Cipher.getInstance("AES");// 创建密码器
            byte[] byteContent = content.getBytes("utf-8");
            cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
            byte[] result = cipher.doFinal(byteContent);
            return result; // 加密
        } catch (Exception e) {
            e.printStackTrace();

        }
        return null;
    }
p
//秘钥和加密内容长度都必须是16的倍数不够就必须补上
 public static byte[] AESencrypt2(String content, String password) {  
             try {  
                     SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");  
                     Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");  
                     byte[] byteContent = content.getBytes("utf-8");  
                     cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化  
                     byte[] result = cipher.doFinal(byteContent);  
                     return result; // 加密  
             } catch (Exception e) {  
                     e.printStackTrace();  
               
             
             }  
             return null;  
     }  

/////////////////////////////aes #33

 public static byte[] ency333(String paramString1, String paramString2, String paramString3)
    {
        if ((paramString1 == null) || (paramString1.length() == 0)) {
            return null;
        }
        IvParameterSpec paramString30 = new IvParameterSpec(paramString3.getBytes());
        SecretKeySpec paramString20 = new SecretKeySpec(paramString2.getBytes(), "AES");
        try
        {
            Cipher localCipher = Cipher.getInstance("AES/CBC/NoPadding");
            localCipher.init(1, paramString20, paramString30);

            byte[]  ret = localCipher.doFinal(paramString1.getBytes());
            return ret;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }
	无论在加密后经过怎么处理下次回来的时候还是那个得到的byte[]就可以了
	如果是new String后乱码  直接getbyte()会出问题的  所以还是stringtobyte和bytetoString好
	byte[] ret = ency("T9&m6OHpo%AYm$oMT9&m6OHpo%AYm$oM", "YJm8T!uw2Wo^Yi80", "T9&m6OHpo%AYm$oM");
	byte[] ret2 =decy(ret, "YJm8T!uw2Wo^Yi80", "T9&m6OHpo%AYm$oM");
	如果ret被byteArrayToHexString()
	那么hexStringToByteArray()就可以了
	public static byte[] decy333(byte[] paramString1, String paramString2, String paramString3)
    {

        IvParameterSpec paramString30 = new IvParameterSpec(paramString3.getBytes());
        SecretKeySpec paramString20 = new SecretKeySpec(paramString2.getBytes(), "AES");
        try
        {
            Cipher localCipher = Cipher.getInstance("AES/CBC/NoPadding");
            localCipher.init(2, paramString20, paramString30);

            byte[] ret = localCipher.doFinal(paramString1);
            return ret;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }
//////////////////////////sha1

     public static String getSha1(String str){
        if (null == str || 0 == str.length()){
            return null;
        }
        char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
            mdTemp.update(str.getBytes("UTF-8"));

            byte[] md = mdTemp.digest();
            int j = md.length;
            char[] buf = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
                buf[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(buf);
        } catch (Exception e) {
            e.printStackTrace();

        }

        return null;
    }
	
	
	
	
}////end class
